package com.jxb.proxy;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.NameMatchMethodPointcut;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

import com.jxb.bojiaoMybatis.BojiaoMybatisScan;
import com.jxb.service.UserService;

/**
 * 类注释
 *
 * @author jiaobo
 * @date Created in 2024/11/24 16:48
 **/
@Configuration
@EnableAspectJAutoProxy//spring AOP
// @ComponentScan(value = "com.jxb")
public class ProxyConfig {

//    @Bean
//    public ProxyFactoryBean userServiceProxy() {
//        UserService userService = new UserService();
//        ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
//        proxyFactoryBean.setTarget(userService);
//        // proxyFactoryBean.addAdvice(new MethodInterceptor() {
//        //     @Override
//        //     public Object invoke(MethodInvocation invocation) throws Throwable {
//        //         System.out.println("before...");
//        //         Object result = invocation.proceed();
//        //         System.out.println("after...");
//        //         return result;
//        //     }
//        // });
//        proxyFactoryBean.addAdvice(new BojiaoMethodInterceptor());
//        return proxyFactoryBean;
//    }

    // @Bean
    // public MethodInterceptor zhouyuAroundAdvise(){
    //     return new MethodInterceptor() {
    //         @Override
    //         public Object invoke(MethodInvocation invocation) throws Throwable {
    //             System.out.println("before...");
    //             Object result = invocation.proceed();
    //             System.out.println("after...");
    //             return result;
    //         }
    //     };
    // }
    //
    // @Bean
    // public ProxyFactoryBean userService(){
    //     UserService userService = new UserService();
    //
    //     ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
    //     proxyFactoryBean.setTarget(userService);
    //     proxyFactoryBean.setInterceptorNames("zhouyuAroundAdvise");
    //     return proxyFactoryBean;
    // }

    // @Bean
    // public BeanNameAutoProxyCreator beanNameAutoProxyCreator() {
    //     BeanNameAutoProxyCreator beanNameAutoProxyCreator = new BeanNameAutoProxyCreator();
    //     beanNameAutoProxyCreator.setBeanNames("userSe*");
    //     beanNameAutoProxyCreator.setInterceptorNames("zhouyuAroundAdvise");
    //     beanNameAutoProxyCreator.setProxyTargetClass(true);
    //     return beanNameAutoProxyCreator;
    // }

    // @Bean
    // public DefaultPointcutAdvisor defaultPointcutAdvisor() {
    //     NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
    //     pointcut.addMethodName("test");
    //     DefaultPointcutAdvisor defaultPointcutAdvisor = new DefaultPointcutAdvisor();
    //     defaultPointcutAdvisor.setPointcut(pointcut);
    //     defaultPointcutAdvisor.setAdvice(new BojiaoMethodBeforeAdvice());
    //     return defaultPointcutAdvisor;
    // }
    //
    // @Bean
    // public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
    //     DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
    //     return defaultAdvisorAutoProxyCreator;
    // }

    // @Aspect
    // @Component
    // public class ZhouyuAspect {
    //
    //     @Before("execution(public void com.zhouyu.service.UserService.test())")
    //     public void zhouyuBefore(JoinPoint joinPoint) {
    //         System.out.println("zhouyuBefore");
    //     }
    //
    // }


}
